home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-05 | 2.8 KB | 108 lines | [TEXT/PJMM] |
- unit FaceFromPICT;
-
- interface
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Memory, Resources, ToolUtils,
- {$ENDC}
- SAT;
-
- function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
- function GetFaceFromPICTToRect (colorPICTid, bwPICTid, maskPICTid: integer; bounds: Rect): FacePtr;
-
- implementation
-
- function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
- var
- bounds: Rect;
- thePICT, maskPICT: PicHandle;
- theFace: FacePtr;
- savePort: SATPort;
- begin
- SATGetPort(savePort);
- GetFaceFromPICT := nil; {Degfault return value if something goes wrong}
-
- {Get PICTs}
- {IDEA: It should really check if the PICT it loads was loaded already, and if it was, don't dispose it.}
- if gSAT.initDepth > 1 then
- thePICT := GetPicture(colorPICTid)
- else
- thePICT := GetPicture(bwPICTid);
- maskPICT := GetPicture(maskPICTid);
-
- if (thePICT = nil) or (maskPICT = nil) then
- exit(GetFaceFromPICT);
-
- bounds := thePICT^^.picFrame;
- OffsetRect(bounds, -bounds.left, -bounds.top);
-
- {Create face}
- theFace := SATNewFace(bounds);
- if theFace = nil then
- exit(GetFaceFromPICT);
-
- {Draw in the face}
- SATSetPortFace(theFace);
- DrawPicture(thePICT, bounds);
- SATSetPortMask(theFace);
- DrawPicture(maskPICT, bounds);
- {Tell SAT that we are done}
- SATChangedFace(theFace);
-
- {Get rid of the PICTs}
- ReleaseResource(Handle(thePICT));
- ReleaseResource(Handle(maskPICT));
-
- {Return the face.}
- GetFaceFromPICT := theFace;
-
- SATSetPort(savePort);
- end; {GetFaceFromPICT}
-
- {Almost the same function, but loads the face to a desired Rect rather than to the picFrame of the PICT.}
- function GetFaceFromPICTToRect (colorPICTid, bwPICTid, maskPICTid: integer; bounds: Rect): FacePtr;
- var
- thePICT, maskPICT: PicHandle;
- theFace: FacePtr;
- savePort: SATPort;
- begin
- SATGetPort(savePort);
- GetFaceFromPICTToRect := nil; {Degfault return value if something goes wrong}
-
- {Get PICTs}
- {IDEA: It should really check if the PICT it loads was loaded already, and if it was, don't dispose it.}
- if gSAT.initDepth > 1 then
- thePICT := GetPicture(colorPICTid)
- else
- thePICT := GetPicture(bwPICTid);
- maskPICT := GetPicture(maskPICTid);
-
- if (thePICT = nil) or (maskPICT = nil) then
- exit(GetFaceFromPICTToRect);
-
- OffsetRect(bounds, -bounds.left, -bounds.top);
-
- {Create face}
- theFace := SATNewFace(bounds);
- if theFace = nil then
- exit(GetFaceFromPICTToRect);
-
- {Draw in the face}
- SATSetPortFace(theFace);
- DrawPicture(thePICT, bounds);
- SATSetPortMask(theFace);
- DrawPicture(maskPICT, bounds);
- {Tell SAT that we are done}
- SATChangedFace(theFace);
-
- {Get rid of the PICTs}
- ReleaseResource(Handle(thePICT));
- ReleaseResource(Handle(maskPICT));
-
- {Return the face.}
- GetFaceFromPICTToRect := theFace;
-
- SATSetPort(savePort);
- end; {GetFaceFromPICTToRect}
-
- end.